﻿// Decompiled with JetBrains decompiler
// Type: MCM.LightInject.ScopeLoader
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

#nullable disable
namespace MCM.LightInject
{
  [ExcludeFromCodeCoverage]
  internal static class ScopeLoader
  {
    public static readonly MethodInfo GetThisOrCurrentScopeMethod = typeof (ScopeLoader).GetTypeInfo().GetDeclaredMethod("GetThisOrCurrentScope");
    public static readonly MethodInfo GetScopedInstanceMethod = typeof (Scope).GetTypeInfo().GetDeclaredMethod("GetScopedInstance");
    public static readonly MethodInfo ValidateScopeMethod = typeof (ScopeLoader).GetTypeInfo().GetDeclaredMethod("ValidateScope");
    public static readonly MethodInfo ValidateTrackedTransientMethod = typeof (ScopeLoader).GetTypeInfo().GetDeclaredMethod("ValidateTrackedTransient");

    public static object ValidateTrackedTransient(object instance, Scope scope)
    {
      if (instance is IDisposable)
      {
        if (scope == null)
          throw new InvalidOperationException(string.Format("The disposable instance ({0}) was created outside a scope. If 'ContainerOptions.EnableCurrentScope=false',\nthe service must be requested directly from the scope. If `ContainerOptions.EnableCurrentScope=true`, the service can be requested from the container,\nbut either way the scope has to be started with 'container.BeginScope()'", (object) instance.GetType()));
        scope.TrackInstance(instance);
      }
      return instance;
    }

    public static Scope ValidateScope<TService>(Scope scope)
    {
      return scope != null ? scope : throw new InvalidOperationException(string.Format("Attempt to create a scoped instance ({0}) outside a scope. If 'ContainerOptions.EnableCurrentScope=false',\nthe service must be requested directly from the scope. If `ContainerOptions.EnableCurrentScope=true`, the service can be requested from the container,\nbut either way the scope has to be started with 'container.BeginScope()'", (object) typeof (TService)));
    }

    public static Scope GetThisOrCurrentScope(Scope scope, IScopeManager scopeManager)
    {
      return scope != null ? scope : scopeManager.CurrentScope;
    }
  }
}
